home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group94a.txt
/
000020_icon-group-sender _Fri Jan 14 06:24:08 1994.msg
< prev
next >
Wrap
Internet Message Format
|
1994-08-19
|
2KB
Received: by cheltenham.cs.arizona.edu; Thu, 20 Jan 1994 09:07:54 MST
Date: 14 Jan 94 06:24:08 GMT
From: organpipe.uug.arizona.edu!CS.Arizona.EDU!not-for-mail@uunet.uu.net (Nevin Liber)
Organization: University of Arizona CS Department, Tucson AZ
Subject: Re: Need help outputing to file
Message-Id: <2h5dq8$h5m@caslon.CS.Arizona.EDU>
References: <9401132354591.dligda.DLITE@delphi.com>
Sender: icon-group-request@cs.arizona.edu
To: icon-group@cs.arizona.edu
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
In article <9401132354591.dligda.DLITE@delphi.com>,
David Ligda <dligda@delphi.com> wrote:
>procedure main(args)
> in := open(args[1]) | stop("Can't open input file")
> out := open(args[2], "w") | stop("cannot open output file")
This assigns "out" with a value of type "file".
> while out := read(in) do {
Here is the bug. This overwrites the old value of "out" with a value
of type "string" (the first line of the input file).
> write(out)
Since "out" is not of type "file", write() writses its output to the
default stream &output.
One way to fix this is to use a different variable to keep the line of
the file currently being worked on. For example:
while line := read(in) do {
write(out, line)
}
There are ways to do this as a one-liner, such as:
while write(out, read(in))
But it might seem more confusing at first.
--
Nevin ":-)" Liber nevin@cs.arizona.edu (602) 293-2799
^^^ (520) after 3/95